package com.twenty.seven.apollo.demo.netty;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;

public class SelvenSocketClient {

    public static void main(String[] args) throws IOException, InterruptedException {
        Socket socket = new Socket("localhost",9999);
        OutputStream outputStream = socket.getOutputStream();

        byte[] request = new byte[220];
        byte[] userId = "10000000000".getBytes();
        byte[] content = "你大爷还是你大爷，你二大爷也还是你二大爷".getBytes();
        System.arraycopy(userId,0,request,0,10);
        System.arraycopy(content,0,request,10,content.length);

        CountDownLatch countDownLatch = new CountDownLatch(10);
        for(int i = 0;i<10;i++){
            new Thread(()->{
                try{
                    outputStream.write(request);
                }catch (IOException e){
                    e.printStackTrace();
                }
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();
        Thread.sleep(2000L);
        socket.close();
    }
}
